$(document).ready(function() {
    $.getJSON('/backend/get-data?data=sale-sale-daily', function(data) {
        sale_chart('sale-daily', 'Daily Sale Trend', data.labels, data.counts, data.figures)
    })


    function lazy_load(section_id, title) {
        $('a[href="#'+section_id+'"]').click(function(e) {
            if(! $(this).data('shown')) {
                $(this).data('shown', true)
                $.getJSON('/backend/get-data?data=sale-'+section_id, function(data) {
                    sale_chart(section_id, title, data.labels, data.counts, data.figures)
                })
            }
        })
    }

    lazy_load('reservation-daily', 'Daily Reservation Trend')
    lazy_load('sale-monthly', 'Monthly Sale Trend')
    lazy_load('reservation-monthly', 'Monthly Reservation Trend')
})
